package com.zhj.agent.core;


import net.bytebuddy.matcher.ElementMatcher;

import lombok.extern.slf4j.Slf4j;

/**
 * 自定义类型匹配器
 */
@Slf4j
public class ProtectiveShieldMatcher<T> extends ElementMatcher.Junction.AbstractBase<T> {

    /** Element matcher */
    private final ElementMatcher<? super T> elementMatcher;

    /**
     * Protective shield matcher
     *
     * @param elementMatcher element matcher
     * @since 1.0.0
     */
    public ProtectiveShieldMatcher(ElementMatcher<? super T> elementMatcher) {
        this.elementMatcher = elementMatcher;
    }

    /**
     * Matches
     *
     * @param target target
     * @return the boolean
     * @since 1.0.0
     */
    @Override
    public boolean matches(T target) {
        try {
            return this.elementMatcher.matches(target);
        } catch (Throwable t) {
            log.warn("匹配增强类失败：{}", t.getMessage());
            return false;
        }
    }
}
